
//  var rootPath = "http://localhost:8090/manage-sys" ;

// var idCard = localStorage.getItem("manage-system-backed-idCard");

$(function () {

    var adminAcc = new AdminAcc();

    adminAcc.start();


});


class AdminAcc {
    constructor() {

        this.load = this;
        this.account = new Account();
        this.pageInd = 1;
        this.rowCount = 100;
        this.mgTeacherCard = new MgTeacherCard();

        this.myTeacherList= new MyTeacherList();

        this.adminTea = new AdminTeacher();

        this.adminStud = new AdminStudent();

        this.ridTable = new TeacherRidTable("id-body-teacher-tab-rid-table","filter-body-teacher-tab-rid-table"); 

        this.courseLists = new CourseList("id-layui-body-course","id-body-course-table","filter-body-course-table"); 

        this.pwdchange = new PwdManage("id-layui-body-personalCenter-pwd","id-layui-body-personalCenter-pwd-form");

    }

    start() {

        var load = this;

        this.account.loadAccount();

        $("#main-layui-body").show();

        $("#admin-side-acc-manage-teacher").on("click", function () { load.loadManageTeacher(); return false; });

        $("#admin-side-acc-manage-student").on("click",function(){  load.loadManageStud();  return false});

        $("#admin-side-acc-manage-course").on("click",function(){  load.loadManageCourse();  return false});

        $("#admin-side-acc-manage-course").on("click",function(){  load.loadManageCourse();  return false});

        $("#admin-side-acc-manage-pwdchange").on("click",function(){  load.loadPwdManage(); return false;  });

        $("#id-layui-nav-rig-quit").on("click",function(){
            MyUtils.quitAcc();
            return false;
        })

        $("#admin-side-acc-manage-teacher").click();
        $("#admin-side-acc-manage-teacher").click();




    }

    teacherCardStart(){
        var load = this;
        console.log("load=");
        console.log(load);

        $.get("/Lock/GetSomeAcc",
            { pageInd: load.pageInd, rowCount: load.rowCount, accrank: 2 },
            function (req) {
                console.log("loadManageTeacherCard");
                console.log(req);

                load.renderManageTeacherCard(req.teachers);

                load.mgTeacherCard.startCard();

            }
        )
    }

    loadManageTeacher() {

        

        $(".layui-body-teacher").show().siblings().hide();
        $(".layui-body-teacher-card").show().siblings().hide();
        $(".layui-body-teacher .layui-body-teacher-tab").show().siblings().hide();

        $(".layui-body-teacher ").show();
        var load = this;
        // console.log("load=");
        // console.log(load);

        // $.get("/Lock/GetSomeAcc",
        //     { pageInd: load.pageInd, rowCount: load.rowCount, accrank: 2 },
        //     function (req) {
        //         console.log("loadManageTeacherCard");
        //         console.log(req);

        //         load.renderManageTeacherCard(req.teachers);

        //         load.mgTeacherCard.startCard();

        //     }
        // )

        console.log("first---click");

        load.teacherCardStart();


        layui.use('element', function(){
            var element = layui.element;
            
         
            var tableLoadFlag = false;//教师名单的表格是否被加载过
            element.on('tab(layui-filter-body-teacher-tab)', function(data){
                if(data.index == 0){
                    load.teacherCardStart();
                }
                else if(data.index == 1){
                    load.myTeacherList.start();
                }else if(data.index == 2){
                    load.ridTable.start();
                }

                

                
              });

          });



    }

    // 渲染教师卡片
    renderManageTeacherCard(req) {

        console.log("-------------- renderManageTeacherCard ----------------")

        // var template = require('art-template');

        var htmlstr = "";
        // for(let j=0;j<10;j++)
        for (let i = 0; i < req.length; i++) {
            if (i % 4 == 0) {
                if (i != 0) htmlstr += "</div>";
                htmlstr += " <div class=\"teacher-col layui-row \">";
            }

            htmlstr += template("tp-admin-side-acc-manage-teacher-card", req[i]);

        }

        $(".layui-body-teacher-card").html(htmlstr);

        for (let i = 0; i < req.length; i++) {
            $(".admin-mg-teacher-card")[i].tid = req[i].aid;
        }


        console.log("-------------- renderManageTeacherCard end ----------------")
    }


// 渲染学生部分
    loadManageStud(){

        $("#id-layui-body-stud").show().siblings().hide();

        this.adminStud.start();

    }

// 加载课程管理
    loadManageCourse(){
        $("#id-layui-body-course").show().siblings().hide();

        this.courseLists.start();

    }


    loadPwdManage(){
        this.pwdchange.start();
    }
}






